package com.points.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.points.system.domain.PointsOperationLog;
import com.points.system.mapper.PointsOperationLogMapper;
import com.points.system.service.PointsOperationLogService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class PointsOperationLogServiceImpl implements PointsOperationLogService {

    private final PointsOperationLogMapper pointsOperationLogMapper;

    @Override
    public void recordLog(PointsOperationLog log) {
        pointsOperationLogMapper.insert(log);
    }

    @Override
    public IPage<PointsOperationLog> getUserPointsLogs(Long userId, Integer pageNum, Integer pageSize) {
        return pointsOperationLogMapper.selectPage(
            new Page<>(pageNum, pageSize),
            new LambdaQueryWrapper<PointsOperationLog>()
                .eq(PointsOperationLog::getUserId, userId)
                .orderByDesc(PointsOperationLog::getCreatedTime)
        );
    }
} 